﻿namespace LeetCodeProject._0001_1000._001_100._91_100._094;

public class Solution
{
    public IList<int> InorderTraversal(TreeNode root)
    {
        if (root == null)
            return Array.Empty<int>();

        var stack = new Stack<TreeNode>();
        var result = new List<int>();
        while (root != null || stack.Count > 0)
        {
            if (root == null)
            {
                root = stack.Pop();
                result.Add(root.val);
                root = root.right;
            }
            else
            {
                stack.Push(root);
                root = root.left;
            }
        }

        return result;
    }
}